#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
class InetAddr
{
public:
	InetAddr(){};
	InetAddr(const struct sockaddr_in& addr)
		:_addr(addr)
	{
		_port = ntohs(_addr.sin_port);
		char ip_buf[32];
		inet_ntop(AF_INET,&_addr.sin_addr,ip_buf,sizeof(ip_buf));//自己提供转换后的ip的空间，防止多进程访问公共资源出现问题
		_ip = ip_buf;
	};
	uint16_t Port()
	{
		return _port;
	};
	const std::string Ip()
	{
		return _ip;
	};
	bool operator==(InetAddr& addr)
	{
		return addr._ip==_ip&&addr._port==_port;
	};
	struct sockaddr_in Addr()
	{
		return _addr;
	};
	std::string AddrStr()
	{
		return _ip+":"+std::to_string(_port);
	};


private:
	uint16_t _port;
	std::string _ip;
	struct sockaddr_in _addr;
};
